using System;
using System.Collections;
using System.Collections.Specialized;
using System.Text;
using NHibernate;

namespace Sedna.Core.Persistence.Hql
{
    public class HqlUtil
    {
        private HqlUtil()
        {
        }

        public static string GetInClause(ICollection paramNames)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("(");
            foreach (string name in paramNames)
            {
                builder.Append(":").Append(name).Append(",");
            }
            builder.Remove(builder.Length - 1, 1);
            builder.Append(")");
            return builder.ToString();
        }

        public static IDictionary GenerateNames(string namePrefix, ICollection parameters)
        {
            IDictionary name2value = new ListDictionary();
            int i = 0;
            foreach (object param in parameters)
            {
                name2value.Add(namePrefix + i++, param);
            }
            return name2value;
        }

        public static IQuery SetParams(IQuery query, IDictionary parameters)
        {
            foreach (DictionaryEntry name2valuePair in parameters)
            {
                query.SetParameter((string)name2valuePair.Key, name2valuePair.Value);
            }
            return query;
        }

    }
}
